package Download;

import java.io.FileNotFoundException;
import java.io.IOException;

import DAO.L_likeDAO;
import DAO.SongDOA;
import DAO.Song_ListDAO;
import each_class.Album;
import each_class.RanKingClass;
import each_class.SongClass;
import each_class.User;

public class FavorDow {

	public static void favorDow(User us, SongClass songClass) throws Exception { // 收藏或下载

		if (songClass != null && us != null) {

			// System.out.println(songClass);
			if (songClass.isDownload()) {
				if (DowMusic.DowMusic(songClass, us)) {
					SongDOA.addSong(songClass);
					Song_ListDAO.addSong(us, us.getUser_id(), songClass.getSong_id());
				}
			}

			if (songClass.isFavorite()) {
				DowMusic.DowMusic(songClass, us);
				SongDOA.addSong(songClass);
				L_likeDAO.addI_Like_song(us.getUser_id(), songClass.getSong_id());
			}

		}

	}

	public static void favorDow(User us, RanKingClass rkc) throws Exception { // 收藏歌单
		if (rkc != null && us != null) {
			Song_ListDAO.addSong_list(us, rkc);
			for (SongClass songClass : rkc.getSongList()) {
				Song_ListDAO.addSong(us, rkc.getId(), songClass.getSong_id());
			}
		}
	}

	public static void favorDow(Album album, User us) throws Exception { // 收藏专辑
		if (album != null && us != null) {
			Song_ListDAO.addSong_list(us, album);
			for (SongClass songClass : album.getsClasses()) {
				Song_ListDAO.addSong(us, album.getAlbm_id(), songClass.getSong_id());
			}
		}

	}
}